package com.ansion.user.beanforui;

import android.text.TextUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.ansion.utils.hanzi2pinyin.Hanzi2Pinyin;

import java.io.Serializable;
import java.util.List;
import java.util.Objects;


/**
 * created by zhaoyuntao
 * on 11/08/2021
 * description: for user and group also.
 */
public class ContactInfo implements Serializable, Comparable<ContactInfo> {

    private String uid;
    private String tag;
    private String displayName;
    private String avatarUrl;
    private boolean isVip;
    private boolean isBadgeWallet;
    private long walletExpireDate;
    private long vipExpireDate;
    private boolean isGroupVoip;
    private int memberCount;
    private char firstEnglishCharacter;
    private String oaId;
    private boolean meInGroup;
    private String oaIcon;
    private int oaSubType;

    private String email;
    private String phoneNumber;
    private String ucid;
    private String nickName;
    private String contactModelDisplayName;
    private String contactModelDisplayNameFormat;
    private int contactId;
    private boolean blocked;
    private List<ContactInfo> members;
    private List<String> admins;

    private String displayNote;

    private String firstName;
    private String lastName;

    private String avatarDisplayText;
    /***
     * 是否是app用户
     */
    private boolean isAppUser = true;

    /***
     * 数据库是否存在该记录
     */
    private boolean dbExist = true;



    private long lastUpdateTime;
    private String ucId;
    private String wallpaperImgPath;
    private int isBabaForSort;
    private String sortKey;
    private boolean isSymbol;
    private boolean isArabic;

    public String getUcid() {
        return ucid;
    }

    public void setUcid(String ucid) {
        this.ucid = ucid;
    }


    public void setTag(String tag) {
        this.tag = tag;
    }

    public String getTag() {
        return tag;
    }

    public String getUid() {
        return uid;
    }

    public void setUid(String uid) {
        this.uid = uid;
    }

    public String getDisplayName() {
        return displayName;
    }

    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    public void setAvatarUrl(String avatarUrl) {
        this.avatarUrl = avatarUrl;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public void setVip(boolean vip) {
        isVip = vip;
    }

    public boolean isVip() {
        return isVip;
    }

    public void setBadgeWallet(boolean isWallet, long walletExpireDate) {
        this.walletExpireDate = walletExpireDate;
        this.isBadgeWallet = isWallet;
    }

    public boolean isBadgeWallet() {
        return isBadgeWallet;
    }

    @Override
    public boolean equals(@Nullable Object obj) {
        if (obj instanceof ContactInfo) {
            return TextUtils.equals(((ContactInfo) obj).getUid(), getUid());
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hash(uid);
    }

    public char getFirstCharacter() {

        if (firstEnglishCharacter != ' ') {
            return firstEnglishCharacter;
        }
        if (TextUtils.isEmpty(getDisplayName()))
            return ' ';
        String pinyin = Hanzi2Pinyin.getInstance().getAsString(getDisplayName().substring(0, 1));
        firstEnglishCharacter = pinyin.toUpperCase().charAt(0);
        boolean isNumberOrEnglishCharacter =
                (firstEnglishCharacter >= '0' && firstEnglishCharacter <= '9')
                        || (firstEnglishCharacter >= 'a' && firstEnglishCharacter <= 'z')
                        || (firstEnglishCharacter >= 'A' && firstEnglishCharacter <= 'Z');
        if (!isNumberOrEnglishCharacter) {
            firstEnglishCharacter = '#';
        }
        return firstEnglishCharacter;
    }


    @Override
    public int compareTo(ContactInfo o) {
        if (o.getFirstCharacter() == '#') {
            return 2;
        } else {
            return Integer.compare(getFirstCharacter(), o.getFirstCharacter());
        }
    }

    public boolean isGroupVoip() {
        return isGroupVoip;
    }

    public void setGroupVoip(boolean groupVoip) {
        isGroupVoip = groupVoip;
    }

    public int getMemberCount() {
        return memberCount;
    }

    public void setMemberCount(int memberCount) {
        this.memberCount = memberCount;
    }

    public String getOaId() {
        return oaId;
    }

    public void setOaId(String oaId) {
        this.oaId = oaId;
    }

    public void setMeInGroup(boolean meInGroup) {
        this.meInGroup = meInGroup;
    }

    public boolean isMeInGroup() {
        return meInGroup;
    }

    public void setVipExpireDate(long vipExpireDate) {
        this.vipExpireDate = vipExpireDate;
    }

    public long getVipExpireDate() {
        return vipExpireDate;
    }

    public void setOaIcon(String oaIcon) {
        this.oaIcon = oaIcon;
    }

    public String getOaIcon() {
        return oaIcon;
    }

    public void setOaSubType(int oaSubType) {
        this.oaSubType = oaSubType;
    }

    public int getOaSubType() {
        return oaSubType;
    }


    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }



    public int getContactId() {
        return contactId;
    }

    public ContactInfo setContactId(int contactId) {
        this.contactId = contactId;
        return this;
    }

    public boolean isBlocked() {
        return blocked;
    }

    public ContactInfo setBlocked(boolean blocked) {
        this.blocked = blocked;
        return this;
    }

    public void setMembers(List<ContactInfo> members) {
        this.members = members;
    }

    public List<ContactInfo> getMembers() {
        return members;
    }

    public List<String> getAdmins() {
        return admins;
    }

    public ContactInfo setAdmins(List<String> admins) {
        this.admins = admins;
        return this;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getDisplayNote() {
        return displayNote;
    }

    public void setDisplayNote(String displayNote) {
        this.displayNote = displayNote;
    }

    public boolean isAppUser() {
        return isAppUser;
    }

    public void setAppUser(boolean appUser) {
        isAppUser = appUser;
    }


    public boolean isDbExist() {
        return dbExist;
    }

    public void setDbExist(boolean dbExist) {
        this.dbExist = dbExist;
    }




    public void setLastUpdateTime(long lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }
    public void setUcId(String ucId) {
        this.ucId = ucId;
    }

    public String getUcId() {
        return ucId;
    }



    public String getAvatarDisplayText() {
        return avatarDisplayText;
    }

    public void setAvatarDisplayText(String avatarDisplayText) {
        this.avatarDisplayText = avatarDisplayText;
    }

    public int isBabaForSort() {
        return isBabaForSort;
    }

    public ContactInfo setIsBabaForSort(int isBabaForSort) {
        this.isBabaForSort = isBabaForSort;
        return this;
    }

    public String getSortKey() {
        return sortKey;
    }

    public ContactInfo setSortKey(String sortKey) {
        this.sortKey = sortKey;
        return this;
    }

    public boolean isSymbol() {
        return isSymbol;
    }

    public ContactInfo setSymbol(boolean symbol) {
        isSymbol = symbol;
        return this;
    }

    public boolean isArabic() {
        return isArabic;
    }

    public ContactInfo setArabic(boolean arabic) {
        isArabic = arabic;
        return this;
    }

    public void setWallpaperImgPath(String wallpaperImgPath) {
        this.wallpaperImgPath = wallpaperImgPath;
    }

    public String getWallpaperImgPath() {
        return wallpaperImgPath;
    }

    @NonNull
    @Override
    public String toString() {
        return "\nContactInfo{name:" + displayName + " isAppUser:" + isAppUser + " uid:" + uid + " phone:" + phoneNumber + " email:" + email + " avatar:" + avatarUrl + "}";
    }
}
